//MDM000402(SKU数据处理)

$(function () {
    Init();
})

function Init() {
    //获取用户操作
    var pattern = new RegExp(/\?Code=(\S*)/g);
    var idx = pattern.exec(window.location.href);
    if (idx) {
        var Code = idx[1];
        params.Content = {
            "Code": Code
        };
        params.Method = "Q";
        $.post(
            mdmPath + "/MDM0004/MDM000403",
            params,
            function (re) {
                if (re.Status == 200) {
                    $("#ItemCode").val(re.Content.Code).attr("disabled", "disabled");    //代码
                    $("#ItemProductName").val(re.Content.ProductName);    //产品名称
                    $("#ItemName").val(re.Content.Name);    //描述
                    $("#ItemPutaway").val(re.Content.Putaway);   //是否上架
                    $("#ItemBrand").val(re.Content.Brand);  //品牌
                    $("#ItemMainproperty").val(re.Content.Mainproperty);    //核心规格
                    $("#ItemProductManager").val(re.Content.ProductManager);    //产品经理
                    $("#ItemPurchaser").val(re.Content.Purchaser);  //采购员
                    $("#ItemCategory1").val(re.Content.Category1);  //一级分类
                    $("#ItemCategory2").val(re.Content.Category2);  //二级分类
                    $("#ItemCategory3").val(re.Content.Category3);  //三级分类
                    $("#ItemUnit").val(re.Content.Unit);    //库存单位
                    $("#ItemManufactureNO").val(re.Content.ManufactureNO);  //制造商物料号
                    $("#ItemManLocation").val(re.Content.ManLocation);  //制造商产地
                    $("#ItemPackage").val(re.Content.Package);  //包装
                    $("#ItemOffline").val(re.Content.Offline);  //是否上目录
                    $("#ItemVatGroup").val(re.Content.VatGroup);    //销项税   
                    $("#ItemPurCircle").val(re.Content.PurCircle);  //采购周期
                    $("#ItemKeyWord").val(re.Content.KeyWord);  //推广关键字

                    $("#createDate").val(re.Content.CreateDate);    //创建时间
                    $("#updateDate").val(re.Content.UpdateDate);    //更新时间
                    $("#createUser").val(re.Content.CreateUser);    //创建用户
                    $("#updateUser").val(re.Content.UpdateUser);    //更新用户
                } else if (re.Status == -999) {
                    alert_QX($('body'), re.Message);
                } else {
                    alert(re.Message)
                }
            }
        );
        $("#MDM0403_table").jqGrid({
            url: mdmPath + "/MDM0004/MDM000403",
            mtype: "post",
            datatype: "json",
            colModel: [
                {label:'代码', name:'Code', sortable:false},
                {label:'规格代码', name:'PropertyCode', sortable:false},
                {label:'规格名称', name:'PropertyName', sortable:false},
                {label:'值', name:'Value', sortable:false},
                {label:'名称', name:'PropertyName', sortable:false},
                // {label:'创建时间', name:'CreateDate', sortable:false},
                // {label:'更新时间', name:'UpdateDate', sortable:false},
                {label:'创建用户', name:'CreateUser', sortable:false},
                {label:'更新用户', name:'UpdateUser', sortable:false}
            ],
            viewrecords: true,
            styleUI : 'Bootstrap',
            height: '100%',
            autowidth: true,  
            shrinkToFit: true,
            scrollOffset: 2,
            rowNum: 10,
            sortname: 'Code',
            rownumbers: true,
            //rowList: [10, 20, 50, 100],
            //pager: "#MDM0403_pager",  
            jsonReader: {
                repeatitems: false,
                root: "Content.MDM000403"
            },
            beforeRequest: function(){
                var grid = $(this);
                var page = grid.jqGrid("getGridParam", "page");
                grid.jqGrid("setGridParam",{
                    postData:{
                        "Tonken": params.Tonken,
                        "BrowserID": params.BrowserID,
                        "Method": "Q",
                        "Content": {
                            "Code": Code
                        } 
                    }
                });
            },  
            loadComplete: function(){
                $("#MDM0403_table").setGridWidth($(".u_content_wrapper .u_panes").width()-30);
            }
        });
        $("#MDM0405_table").jqGrid({
            url: mdmPath + "/MDM0004/MDM000403",
            mtype: "post",
            datatype: "json",
            colModel: [
                {label:'代码', name:'Code', sortable:false},
                {label:'行号', name:'LineID', sortable:false},
                {label:'审批备注', name:'Memo', sortable:false},
                {label:'审批状态', name:'Status', sortable:false},
                // {label:'创建时间', name:'CreateDate', sortable:false},
                // {label:'更新时间', name:'UpdateDate', sortable:false},
                {label:'创建用户', name:'CreateUser', sortable:false},
                {label:'更新用户', name:'UpdateUser', sortable:false}
            ],
            viewrecords: true,
            styleUI : 'Bootstrap',
            height: '100%',
            autowidth: true,  
            shrinkToFit: true,
            scrollOffset: 2,
            rowNum: 10,
            sortname: 'Code',
            rownumbers: true,
            //rowList: [10, 20, 50, 100],
            //pager: "#MDM0405_pager",  
            jsonReader: {
                repeatitems: false,
                root: "Content.MDM000405"
            },
            beforeRequest: function(){
                var grid = $(this);
                var page = grid.jqGrid("getGridParam", "page");
                grid.jqGrid("setGridParam",{
                    postData:{
                        "Tonken": params.Tonken,
                        "BrowserID": params.BrowserID,
                        "Method": "Q",
                        "Content": {
                            "Code": Code
                        } 
                    }
                });
            },  
            loadComplete: function(){
                $("#MDM0405_table").setGridWidth($(".u_content_wrapper .u_panes").width()-30);
            }
        });
    }
};

//MDM000401(SKU数据处理)
/*
    function MDM000401(opt) {
        //获取表单信息
        var Code = $("input[data-field='ItemDocEntry']").val();
        var Title = $("input[data-field='ItemTitle']").val();
        var Category = $("input[data-field='ItemCategory']").val();
        var Content_PC = um_P.getContent();
        var Content_M = um_M.getContent();
        if (opt) {
            params.Method = opt;
            if (opt === 'A') {
                Code = 0;
            }
        }
        params.Content = {
            "Code": Code,
            "Name": Name,
            "Category": Category,
            "Content_PC": Content_PC,
            "Content_M": Content_M,
            "Picture_PC_Code": "",
            "Picture_M_Code": "",
            "Picture_PC_Address": "",
            "Picture_M_Address": ""
        };
        //console.log(params);
        if (Name != '') {
            var lsUrl = mdmPath + "/MDM0017/MDM001701";
            $.ajax({
                type: "post",
                url: lsUrl,
                data: params,
                dataType: "json",
                success: function (re) {
                    //alert(re.Status + re.Message);
                    if (re.Status == 200) {
                        //console.log(re.Status + re.Message)
                        //加载模态框内容
                        WEB.successModal("操作成功");
                        //弹出模态框
                        $("#Modal").modal({
                            backdrop: 'static'
                        });
                        //模态框效果
                        ACTION.Modal();
                    } else {
                        //console.log(re.Status + re.Message);
                        //加载模态框内容
                        WEB.alertModal(re.Message);
                        //弹出模态框
                        $("#Modal").modal({
                            backdrop: 'static'
                        });
                        //模态框效果
                        ACTION.Modal();
                    }
                }
            });
        } else {
            console.log("有关键文本框为空");
            //加载模态框内容
            WEB.alertModal("名称不能为空");
            //弹出模态框
            $("#Modal").modal({
                backdrop: 'static'
            });
            //模态框效果
            ACTION.Modal();
        }
    }
*/
